#include "Element_1D.h"

Point_1::Point_1()
{
    coord = new double [1];
};

Point_1::Point_1(double _x)
{
    coord = new double [1];
    coord[0] = _x;
};

Point_1::Point_1(const Point_1& _p)
{
    coord = new double [1];
    coord[0] = _p.coord[0];
};

Point_1::Point_1(Point_1& p)
{
    coord = new double [1];
    coord[0] = p.coord[0];
};

Point_1::~Point_1()
{
    if (coord != NULL)
	delete [] coord;
};

std::ostream& operator<<(std::ostream& _os, const Point_1 &_p)
{
    if (_p.coord != NULL)
	_os <<  _p.coord[0];
    return _os;
};

Point_1 operator+(const Point_1 &_p1, const Point_1 &_p2)
{
    Point_1 re(_p1.coord[0] + _p2.coord[0]);
    return re;
};

double Point_1::operator()() const
{
    return coord[0];
};

void Point_1::operator()(double _x)
{
    coord[0] = _x;
};

const Point_1& Point_1::operator=(const Point_1 &_p)
{
    if (this != &_p)
	coord[0] = _p.coord[0];
    return *this;
};


MeshGrid::MeshGrid()
{
    no_vertex = 2;
    vertices = new Point_1[no_vertex];
    global_idx = new int[no_vertex];
};

MeshGrid::~MeshGrid()
{
    delete [] vertices;
    delete [] global_idx;
};

void MeshGrid::set_global_idx(int _i, int _idx)
{
    if (_i >= 0 && _i <= 1)
	global_idx[_i] = _idx;
    else
	std::cerr << "In MeshGrid: out of idx range." << std::endl;
};

int MeshGrid::get_global_idx(int _i) const
{
    if (_i >= 0 && _i <= 1)
	return global_idx[_i];
    else
	std::cerr << "In MeshGrid: out of idx range." << std::endl;
};

void MeshGrid::set_vertices(const Point_1 *_pnt_list)
{
    for (int i = 0; i < 2; i++)
	vertices[i] = _pnt_list[i];
};

void MeshGrid::set_vertices(int _i, const Point_1 &_p)
{
    vertices[_i] = _p;
};

const Point_1* MeshGrid::get_vertices() const
{
    return vertices;
};

const Point_1& MeshGrid::get_vertices(int _i) const
{
    return vertices[_i];
};
